package com.dropesoft.biz;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DbHelper extends SQLiteOpenHelper {

	private static final String DB_NAME = "sport_db";
	private static final int DB_VERSION = 1;
	
	
	 
	public DbHelper(Context context) {
		super(context, DB_NAME, null, DB_VERSION);
	}
	
	@Override
	public void onCreate(SQLiteDatabase db) {
		
		// Creazione delle tabelle
		StringBuilder strBuild = new StringBuilder();
		
		// Allenamenti
		strBuild.append(" CREATE TABLE allenamenti ( ");
		strBuild.append(" _id INTEGER PRIMARY KEY,");
		strBuild.append(" user_id TEXT,");
		strBuild.append(" data TEXT NOT NULL,");
		strBuild.append(" descrizione  VARCHAR(100),");
		strBuild.append(" note  VARCHAR(100),");
		strBuild.append(" tempo  REAL,");
		strBuild.append(" distanza  REAL,");
		strBuild.append(" passoMed  REAL,");
		strBuild.append(" velocitaMed  REAL,");
		strBuild.append(" bpmMed  INTEGER,");
		strBuild.append(" colorie  INTEGER,");
		strBuild.append(" dataAggiornamento TEXT NOT NULL,");
		strBuild.append(" esito INTEGER,");
		strBuild.append(" discipline_id INTEGER");
		strBuild.append("  ) ");
		
		db.execSQL(strBuild.toString());
		/*
		// Tipi
		strBuild = new StringBuilder();
		strBuild.append(" CREATE TABLE types ( ");
		strBuild.append(" _id INTEGER PRIMARY KEY,");
		strBuild.append(" internal_name  VARCHAR(20)");
		strBuild.append("  ) ");
		db.execSQL(strBuild.toString());
		
		// Inserisce i valori di default
		strBuild = new StringBuilder();
		strBuild.append(" INSERT INTO types (internal_name) values ('swimming')");
		db.execSQL(strBuild.toString());
		
		strBuild = new StringBuilder();
		strBuild.append(" INSERT INTO types (internal_name) values ('cycling')");
		db.execSQL(strBuild.toString());
		
		strBuild = new StringBuilder();
		strBuild.append(" INSERT INTO types (internal_name) values ('running')");
		db.execSQL(strBuild.toString());
		*/
		
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		// TODO Auto-generated method stub
		
	}
}
